function startOp() {
	$('#hint').animate({
	opacity:.1 },750,function(){
	stopOp();
	});
	setTimeout('startOp()',1500);
}
function stopOp(){ 
$('#hint').animate({ opacity:1 },750);
}
$(document).ready(function(){ 
	setTimeout('startOp()',1500);
	$('#menu button').each(function(){
		$(this).button();
	});
	$('#createdb').live('click',function(){ 
	
	$.ajax({
	url:'setup.php',
	data:({ config:'true', createdb:'true'  }),
	success:function(a) {
	$('#main').append(a);
	setTimeout("location.reload()",2500);
	},
	error:function(a) {
	$('#main').append(a);
	}
	});
	
	
	});
	$('#createtable').click(function(){
		$('#warn').dialog({ autoOpen:true,title:'Are you sure?',modal:true,
			buttons:{
			"No":function() {
					$(this).dialog('destroy');
					},
					"Yes":function(){ 
					$.ajax({ 
			url:'setup.php',
			data:({ createtable:'true',db:$('#db_name').val(),username:$('#a_user').val(),password:$('#a_pass').val()  }),
			success:function(a){ $('#main').text('Settings saved. Reloading page.'); 
			setTimeout("location.reload()",2500);
			$('#main').append(a);
			$(this).dialog('destroy');
			}
		});
		}
		}
	});
	});
	$('#setup').click(function(){
		$('#setupd').dialog({
			autoOpen:true,
			height:'auto',
			width:'450',
			title:'Setup',
			closeOnEscape:true,
			buttons:{
				"Save":function(){
					$.ajax({
						url:'setup.php',
						data:({ setup:'true',server:$('#server:input').val(),juke:$('#juke:input').val(),s_user:$('#s_user:input').val(),s_pass:$('#s_pass:input').val(),db_server:$('#db_server:input').val(),db_name:$('#db_name:input').val(),db_user:$('#db_user:input').val(),db_pass:$('#db_pass:input').val() }),
						success:function(a){ $('#main').text('Settings saved. Reloading page.'); setTimeout("location.reload()",2000); },
						error:function(a){ $('#main').text('There was an error.'); }
					});
				
					username = $('#j_user').val();
					pw = $('#j_pass').val()
					
					$(this).dialog('destroy');
				}
			}
		});
		$('#setupd *:input').css('float','right').css('position','relative').css('top','-4px');
		
		
		
	});
	

	});
	$('#foldersetup').live('click',function(){
	
		
		$(this).removeClass('ui-state-focus');
		$('#foldersetupd').dialog({
			height:'auto',autoOpen:true,width:'375',closeOnEscape:true,title:'Check the appropriate boxes',
			buttons:{'Save':function(){
					$('.musicfolderid').each(function(i){
						if ($('.music:input').eq(i).is(':checked')) {
							$.ajax({ 
								url:'setup.php',
								data:({  config:'true', folder:$('.musicfolderid')[i].getAttribute('id'), music:'true'  }),
								success:function(){ }
							});
						}
						if ($('.video:input').eq(i).is(':checked')) { 
							$.ajax({ 
								url:'setup.php',
								data:({  config:'true', folder:$('.musicfolderid')[i].getAttribute('id'), video:'true'  }),
								success:function(){ }
							});
						}
						$('#foldersetupd').dialog('destroy');
					});
				},
				'Rescan':function() { $.ajax({ url:'setup.php', data:({ rescan:'true' }), success:function(a){ $('#folders').html(a); }  }); displayFolders(); } } });
					 displayFolders(); 
		
		
	
});
function displayFolders() {

$.ajax({ 
			url:'setup.php',
			data:({ config:'true',getfolders:'true' }),
			success:function(a){ 
					a = trim(a);
					var response = new Array();
					response = a.split(' ');
					$('#folders *:input').each(function(i) {
					   
						if (response[i] == 'true') { $(this).attr('checked','checked'); }
					});
				}
			});
}
function trim(string) { return string.replace(/^\s\s*/, '').replace(/\s\s*$/, '');  }
